package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProMainten;
import com.ruoyi.system.service.IProMaintenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目维护Controller
 *
 * @author ruoyi
 * @date 2024-09-30
 */
@RestController
@RequestMapping("/system/mainten")
public class ProMaintenController extends BaseController
{
    @Autowired
    private IProMaintenService proMaintenService;

    /**
     * 查询项目维护列表
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProMainten proMainten)
    {
        startPage();
        List<ProMainten> list = proMaintenService.selectProMaintenList(proMainten);
        return getDataTable(list);
    }

    /**
     * 导出项目维护列表
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:export')")
    @Log(title = "项目维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProMainten proMainten)
    {
        List<ProMainten> list = proMaintenService.selectProMaintenList(proMainten);
        ExcelUtil<ProMainten> util = new ExcelUtil<ProMainten>(ProMainten.class);
        util.exportExcel(response, list, "项目维护数据");
    }

    /**
     * 获取项目维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:query')")
    @GetMapping(value = "/{maintenId}")
    public AjaxResult getInfo(@PathVariable("maintenId") Long maintenId)
    {
        return success(proMaintenService.selectProMaintenByProjectId(maintenId));
    }

    /**
     * 新增项目维护
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:add')")
    @Log(title = "项目维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProMainten proMainten)
    {
        return toAjax(proMaintenService.insertProMainten(proMainten));
    }

    /**
     * 修改项目维护
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:edit')")
    @Log(title = "项目维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProMainten proMainten)
    {
        return toAjax(proMaintenService.updateProMainten(proMainten));
    }

    /**
     * 删除项目维护
     */
    @PreAuthorize("@ss.hasPermi('system:mainten:remove')")
    @Log(title = "项目维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{projectIds}")
    public AjaxResult remove(@PathVariable Long[] projectIds)
    {
        return toAjax(proMaintenService.deleteProMaintenByProjectIds(projectIds));
    }
}
